<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/m/include/init_mobile.jsp" %>
<%@ page import="com.qbooks.member.*" %>
<%
	if (session_user_id.equals("")) {
		response.sendRedirect("/m/member/login.jsp?os="+os);
		return;
	}

	HashMap param = new HashMap();
	param.put("member_id", session_user_id);
	param.put("status", "1");
	
	MemberDAO dao = new MemberDAO();
	HashList info = dao.selectMemberList(param);
	
	if (info.size() == 0) {
		response.sendRedirect("/m/member/login.jsp?os="+os);
		return;
	}
%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
	<title><%= HOME_NAME %></title>
	<%@ include file="/m/include/cssnjs.jsp"  %>
	<link rel="stylesheet" href="/css/jquery.mobile-1.4.2.min.css"/>
	<script type="text/javascript">
	$(document).ready(function() {
		$('#header-nav li:nth-child(4)').addClass('on');
		
		$('.icon-delete').on('click', function() {
			$(this).closest('div').find('input').val('').focus();
			$('.error_message').text('');	
		});
	});
	
	function fnUpdate(gubn) {

		if (gubn == "name") {
			if (document.frm_name.member_name.value == "") {
				document.frm_name.member_name.focus();
				cfShowModal('성명을 입력하세요');
				return false;
			}
		} else if (gubn == "password") {

			if (document.frm_password.member_pw.value == "") {
				document.frm_password.member_pw.focus();
				cfShowModal('비밀번호를 입력하세요');
				return false;
			}
			
			if (document.frm_password.member_pw.value.length < 4) {
				document.frm_password.member_pw.focus();
				cfShowModal('비밀번호는 4~20글자로 입력하세요');
				return false;
			}
		}

		$('.error_message').text('');
		
		$.ajax({
			url: '/member/memberSave.do',
			type: "POST",
		    dataType: 'json',
		    data:$('#frm_'+gubn).serialize(),
		    error: function(data, status, err){
		    	cfShowModal(err);
		    },
			success: function(data){
				if (data.result) {
					cfShowModal('수정되었습니다');
				} else {
					$('.error_message').text('');
				}
		    }
		});
		
		return false;
	}
	
	</script>
</head>
<body>
	<div id="wrap">
		<%@ include file="/m/include/header.jsp"  %>
		<div id="contents" class="ui-page-theme-a">
		
		
			<h2>회원정보변경</h2>
			<div id="login">
		 		<div class="error_message"></div>
            	<form name="frm_name" id="frm_name" method="post" action="" onsubmit="return fnUpdate('name')">
	        		<input type="hidden" name="member_id" value="<%= info.get("member_id",0) %>"/>
	        		<input type="hidden" name="job_type" value="U"/>
		        	<div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset ui-input-has-clear">
		        		<input type="text" name="member_name" value="<%= info.get("member_name",0) %>" maxlength="255" placeholder="성명"/>
		        		<a href="#" class="ui-input-clear ui-btn icon-delete  ui-corner-all" ></a>
		        	</div>
		        	<div class="ui-btn ui-input-btn ui-btn-active ui-corner-all ui-shadow">
						회원명 변경하기<input type="image" alt="변경하기" value="변경하기"/>
					</div>
				</form>
				
				<hr class="divider mt1em mb1em"/>
				
				<form name="frm_password" id="frm_password" method="post" action="" onsubmit="return fnUpdate('password')">
	        		<input type="hidden" name="member_id" value="<%= info.get("member_id",0) %>"/>
	        		<input type="hidden" name="job_type" value="U"/>
		        	<div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset ui-input-has-clear">
		        		<input type="password" name="member_pw" value="" maxlength="20" placeholder="비밀번호(4~20글자)"/>
		        		<a href="#" class="ui-input-clear ui-btn icon-delete ui-corner-all" ></a>
		        	</div>
		        	<div class="ui-btn ui-input-btn ui-btn-active ui-corner-all ui-shadow">
						비밀번호 변경하기<input type="image" alt="비밀번호 변경하기" value="비밀번호 변경하기"/>
					</div>
        		</form>
			</div>
		</div>
		<%@ include file="/m/include/footer.jsp"  %>			
	</div>

</body>

</html>









